<extend name="./Application/Common/View/block/base.php" />
<block name="header">
    <include file="./Application/Admin/View/block/easyui_header.php" />
    <link rel="stylesheet" type="text/css" href="/Public/uploadfy/uploadify.css" />
    <script type="text/javascript" src="/Public/uploadfy/jquery.uploadify.min.js"></script>
    <style>
        #dg{
            height: 100%;;
        }
    </style>
</block>
<block name="bdoy">
    <body>
    <table id="grid_hoist"></table>
    <div id="grid_hoist_ToolBar" style="padding:5px;height:auto">
        <div style="margin-bottom:5px">
            <a id="btnAdd_hoist" href="#" class="easyui-linkbutton" iconCls="icon-add" plain="true">增加</a>
            <a id="btnedit_hoist" href="#" class="easyui-linkbutton" iconCls="icon-edit" plain="true">编辑</a>
            <a id="btnDel_hoist" href="#" class="easyui-linkbutton" iconCls="icon-remove" plain="true">删除</a>
            <a id="btnSearch_hoist" href="#" class="easyui-linkbutton" iconCls="icon-search" plain="true">搜索</a>
            <a id="btnReload" href="#" class="easyui-linkbutton" iconCls="icon-reload" plain="true" onclick="$('#grid_hoist').datagrid({url:'/Manage/AdminPumpHoist/get_all',queryParams:{page:1,rows:20}})">重载</a>
            <a href="#" class="easyui-linkbutton" iconCls="icon_ext icon-import" plain="true" onclick="open_dialog('/Manage/Admin/open_window_import?url=__URL__/import')">导入</a>
            <a href="#" class="easyui-linkbutton" iconCls="icon_ext icon-rescueLog" plain="true" onclick="open_tab('__URL__/export')">导出</a>
        </div>
        <div id="queryParamZone_hoist">
            <form id="queryForm_hoist" method="post" action="">
                <table>
                    <tr>
                        <td>泵站</td>
                        <td><input id="ps_id_combox" name="ps_id"></td>
                        <td>设备属性</td>
                        <td id="table_field">
                            <input class="easyui-combobox"/>
                        </td>
                        <td>查询条件</td>
                        <td id="condition_td">
                            <input type="text"/>
                        </td>

                        <td><a id="btnQuery_hoist" href="#" class="easyui-linkbutton" iconCls="icon-search">查询</a></td>
                        <td><a href="#" class="easyui-linkbutton" iconCls="icon-undo" onclick="javascript:$('#queryForm_press').form('clear');">重置</a></td>
                    </tr>
                </table>
            </form>
        </div>
    </div>
    <div id="hoist_Dlg" class="easyui-dialog" title="" style="width:650px;height:450px;padding:10px" buttons="#dlg_buttons_hoist" closed="true" resizable="true">
        <form id="hoistForm" method="post" action="">
            <input id="saveflag_hoist" name="saveflag_hoist" type="hidden" value="add"/>
            <input id="pump_id" type="hidden" name="id" />
            <table border="0">
                <tr>
                    <td align="right">泵站名称：</td>
                    <td>
                        <input id="ps_id_combox_1" name="ps_id" required="true" style="width: 150px;">
                    </td>
                    <td align="right">起吊设备编码：</td>
                    <td>
                        <input class="easyui-validatebox" validType="maxLength[30]" type="text" name="hoist_id" required="true"></input>
                    </td>
                </tr>
                <tr>
                    <td align="right">起吊设备名称：</td>
                    <td>
                        <input class="easyui-validatebox" validType="maxLength[30]" type="text" name="hoist_name" required="true"></input>
                    </td>
                    <td align="right">生产厂家：</td>
                    <td>
                        <input class="easyui-textbox" type="text" name="hoist_mfr"></input>
                    </td>
                </tr>
                <tr>
                    <td align="right">型号：</td>
                    <td>
                        <input class="easyui-textbox" type="text" name="hoist_model"></input>
                    </td>
                    <td align="right">起吊重量(吨)：</td>
                    <td>
                        <input class="easyui-numberbox" type="text" name="hoist_weight" precision="3"></input>
                    </td>
                </tr>
                <tr>
                    <td align="right">电机功率（千瓦）：</td>
                    <td>
                        <input class="easyui-numberbox" type="text" name="hoist_motor_power" precision="4" style="width: 150px;"></input>
                    </td>
                    <td align="right">投运日期：</td>
                    <td>
                        <input type="text" class=" easyui-datebox" name="hoist_svc_dt" style="width:140px">
                    </td>
                </tr>
                <tr>
                    <td>
                        <input id="hoist_img_button" type="file" multiple="true" value="" />
                    </td>
                    <td colspan="3">
                        <input type="hidden" id="hoist_img" name="hoist_img"/>
                        <img src="__PUBLIC__/img/no_pic.jpg" id="hoist_img_img" width="100" height="200">
                        <script>
                            $('#hoist_img_button').uploadify({
                                'swf'      : '/Public/uploadfy/uploadify.swf',
                                'uploader' : '/Manage/Admin/uploadify',
                                'buttonText' : '上格起吊设备图',
                                'onUploadSuccess' : function(file, data, response) {
                                    $('#hoist_img_img').attr('src', data);
                                    $('#hoist_img').val(data);
                                }
                            });
                        </script>
                    </td>
                </tr>
            </table>
        </form>
    </div>
    <div id="dlg_buttons_hoist" style="text-align: center;">
        <a href="#" class="easyui-linkbutton" iconCls="icon-save" onclick="javascript:submithoistForm();">保存</a>
    </div>
    <form id="batchDelForm_hoist" method="post"></form>
    </body>
</block>
<block name="footExtendJs">
    <script type="text/javascript">
        //$.noConflict();

        $(window).resize(function() {
            $('#grid_hoist').datagrid('resize');
        });
		
		function clear_img(){
			$('#hoist_img_img').attr('src', '__PUBLIC__/img/no_pic.jpg');
		}

        function clearhoistForm(){
            $('#hoistForm').form('clear');
        }

        function clearQueryParamZone(){
            $('#queryForm_hoist').form('clear');
        }

        $(function(){
            $('#ps_id_combox').combobox({
                url:'/Manage/AdminPumpStation/get_all_combox',
                valueField:'id',
                textField:'name',
                width:180,
            });
            $('#grid_hoist').datagrid({
                width: '100%',
                //height: 400,
                fit: true,
                nowrap: false,
                striped: true,
                collapsible:false,
                url:'/Manage/AdminPumpHoist/get_all',
                queryParams:{page:1,rows:20},
                method:'get',
                pageNumber:1,
                pageSize:20,
                idField:'id',
                sortName: 'id',
                sortOrder: 'desc',
                remoteSort: false,
                columns:[[
                    {field:'id',title:'序号',width:60,checkbox:true},
                    {field:'sta_name',title:'泵站名称',width:180,align:'center'},
                    {field:'hoist_id',title:'起吊设备编码',width:100,align:'center'},
                    {field:'hoist_name',title:'起吊设备名称',width:140,align:'center'},
                    {field:'hoist_mfr',title:'生产厂家',width:140,align:'center'},
                    {field:'hoist_model',title:'型号',width:140,align:'center'},
                    {field:'hoist_weight',title:'起吊重量(吨)',width:140,align:'center'},
                    {field:'hoist_motor_power',title:'电机功率(千瓦)',width:140,align:'center'},
                    {field:'hoist_svc_dt',title:'投运日期',width:100,align:'center'},
                ]],
                pagination:true,
                rownumbers:true,
                singleSelect:true,
                toolbar: '#grid_hoist_ToolBar',
                onDblClickRow: function(rowIndex, rowData) {
                    var selected = $('#grid_hoist').datagrid('getSelected');
                    if($('#single').is(":hidden")){
                        edit_hoist(rowData.id);
                    }else{
                        if(selected){
                            if(selected.id == rowData.id){
                                edit_hoist(rowData.id);
                            }else{
                                $.messager.alert('提示','当前选择了多条信息，不可以编辑！','error');
                            }
                        }else{
                            edit_hoist(rowData.id);
                        }
                    }
                },
                onLoadSuccess: function(data) {
                    $(this).datagrid('resize');
//                $('.pump_select').combobox('reload','/Manage/AdminPumpPump/get_all_pump?ps_id='+$('#pumpstation_id').val());
                }
            });

            $('#btnAdd_hoist').click(function() {
                clearhoistForm();
				clear_img();
                $("#saveflag_hoist").val("add");
                $('#ps_id_combox_1').combobox({
                    url:'/Manage/AdminPumpStation/get_all_combox',
                    valueField:'id',
                    textField:'name'
                });
                $('#hoist_Dlg').dialog({title:'录入起吊设备信息',modal:true});
                $('#hoist_Dlg').dialog("open");
            });
            $('#btnedit_hoist').click(function() {
                var selected = $('#grid_hoist').datagrid('getSelected');
                if($('#single').is(":hidden")){
                    if (selected) {
                        edit_hoist(selected.id);
                    }
                }else{
                    var rows = $('#grid_hoist').datagrid('getSelections');
                    if(rows.length == 1 || rows.length == 0){
                        if (selected) {
                            edit_hoist(selected.id);
                        } else{
                            $.messager.show({title: "提示",msg: "请选中一条信息，再进行编辑!"});
                        }
                    } else{
                        $.messager.alert('提示','当前选择了多条信息，不可以编辑！','error');
                    }
                }
            });
            $('#btnDel_hoist').click(function() {
                var ids = [];
                var rows = $('#grid_hoist').datagrid('getSelections');
                for ( var i = 0; i < rows.length; i++) {
                    ids.push(rows[i].id);
                }
                if ((ids != null) && (ids.length > 0)) {
                    $.messager.confirm('请确认', '你确定要删除吗？', function(r) {
                        if (r) {
                            $('#batchDelForm_hoist').ajaxSubmit({
                                url:"/Manage/AdminPumpHoist/deleteArray",
                                data:{'ids':ids.join(',')},
                                dataType:'json',
                                success: function(data) {
                                    console.log(data);
                                    if (data.status==1) {
                                        $('#grid_hoist').datagrid('reload');
                                        $('#grid_hoist').datagrid("unselectAll");
                                        $.messager.show({title:'提示',msg:'删除成功！',showType:'slide'});
                                    }
                                    else $.messager.alert('提示','删除失败！','error');
                                }
                            });

                        }
                    });
                }
            });
            $('#btnSearch_hoist').click(function() {
                $('#queryParamZone_hoist').toggle();
                if($('#queryParamZone_hoist').is(":hidden")){
                    clearQueryParamZone();
                }
                $('#grid_hoist').datagrid("resize");
            });

            $('#btnQuery_hoist').click(function() {
                var obj = $('#queryForm_hoist').serializeJson();
                $('#grid_hoist').datagrid('load',obj);
            });
            var model = 'PumpHoist';
            table_index_change(model, 'base');
            $('#queryParamZone_hoist').hide();
            $('#single').hide();

            /* WdatePicker({el:'pump_mdate',readOnly:true});
             $dp.hide(); */
        });

        function edit_hoist(id) {
            if(id!=""){
                $("#saveflag_hoist").val("update");
            }else{
                clearhoistForm();
                $("#saveflag_hoist").val("add");
                return;
            }
			clear_img();
            $.ajax({url:"/Manage/AdminPumpHoist/get_obj_json",data:{id:id},dataType:"json",success:function(json, textStatus){
                $('#ps_id_combox_1').combobox({
                    url:'/Manage/AdminPumpStation/get_all_combox',
                    valueField:'id',
                    textField:'name'
                });
                $('#hoistForm').form('load',{
                    "id": json.id,
                    'ps_id':json.ps_id,
                    "hoist_id": json.hoist_id,
                    "hoist_name": json.hoist_name,
                    "hoist_model": json.hoist_model,
                    "hoist_mfr": json.hoist_mfr,
                    "hoist_weight": json.hoist_weight,
                    "hoist_motor_power": json.hoist_motor_power,
                    "hoist_svc_dt": json.hoist_svc_dt,
                    "hoist_img": json.hoist_img,

                });
                if(json.hoist_img != ''){
                    $('#hoist_img_img').attr('src', json.hoist_img);
                }
                $('#hoist_Dlg').dialog({title:'编辑起吊设备信息',modal:true});
                $('#hoist_Dlg').dialog("open");
                setFormFocus('#hoistForm');
            },error:function(XMLHttpRequest, textStatus, errorThrown) {
                relogin(XMLHttpRequest, textStatus, errorThrown);
            }});
        }

        function submithoistForm() {
            if ($('#hoistForm').form('validate')) {
                var submitflag = $("#saveflag_hoist").val();
                var url = "";
                if (submitflag === "add")
                    url = "/Manage/AdminPumpHoist/add";
                if (submitflag === "update")
                    url = "/Manage/AdminPumpHoist/edit";
                $('#hoistForm').ajaxSubmit({
                    url:url,
                    dataType:'json',
                    success: function(data) {
                        if (data.status==1) {
                            if (submitflag === "add") $('#grid_hoist').datagrid('load');
                            if (submitflag === "update") $('#grid_hoist').datagrid('reload');
                            $('#hoist_Dlg').dialog("close");
                            $.messager.show({title:'提示',msg:'保存成功！',showType:'slide'});
                        }
                        else $.messager.alert('提示','操作失败！\n原因：'+data.msg,'error');
                    }
                });
            }
        }
    </script>
</block>
